﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using DBUtility;
using IDAL;
using Model;

namespace DAL
{    
    /// <summary>
    /// 客户端软件列表类
    /// </summary>
    public class ClientSoftware : BaseRepository<ClientSoftwareInfo>, IClientSoftware
    {
        #region 静态变量部分
        private const string PARM_CLIENTSOFT_CSID = "@CSID";
        private const string PARM_CLIENTSOFT_CSNAME = "@CSName";
        #endregion

        #region 数据检索部分
        public IList<ClientSoftwareInfo> LoadEntities()
        {
            return ExcuteSqlToGetEntities("ClientSoftware_select");
        }

        /// <summary>
        /// Get an individual category based on a provided id
        /// </summary>
        /// <param name="categoryId">Category id</param>
        /// <returns>Details about the Category</returns>
        public ClientSoftwareInfo LoadEntity<T1>(T1 cSID)
        {
            SqlParameter parm = GetParameter();
            //Bind the parameter
            parm.Value = cSID;
            return ExcuteSqlToGetEntity("ClientSoftware_selectbyID", parm);
        }

        public ClientSoftwareInfo GetClientSoftwarebyName(string cSName)
        {
            SqlParameter parm = new SqlParameter(PARM_CLIENTSOFT_CSNAME, SqlDbType.NVarChar, 50);
            parm.Value = cSName;
            return ExcuteSqlToGetEntity("ClientSoftware_selectbyName", parm);
        }
        #endregion


        #region 重写基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override ClientSoftwareInfo GetEntityRecord(SqlDataReader rdr)
        {
            ClientSoftwareInfo pro = new ClientSoftwareInfo()
                {
                    CSID = rdr.GetInt32(0),
                    CSName = rdr.GetValue(1).ToString()
                };
            return pro;
        }

        public override ClientSoftwareInfo GetEntityRecord()
        {
            ClientSoftwareInfo pro = new ClientSoftwareInfo();
            return pro;
        }

        public override string GetInsertsp()
        {
            return "ClientSoftware_Insert";
        }

        public override string GetUpdatesp()
        {
            return null;
        }

        public override string GetDeletesp()
        {
            return "ClientSoftware_Delete";
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_CLIENTSOFT_CSID, SqlDbType.Int, 4);
            return Parm;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_CLIENTSOFT_CSID, SqlDbType.Int, 4),
					new SqlParameter(PARM_CLIENTSOFT_CSNAME, SqlDbType.NVarChar, 50)
                };
            return parms;
        }

        public override void SetParameters(ClientSoftwareInfo productType, params SqlParameter[] Parms)
        {
            Parms[0].Value = productType.CSID;
            Parms[1].Value = productType.CSName;
        }
        #endregion
    }
    

    /// <summary>
    /// 客户端软件信息类
    /// </summary>
    public class ClientSoft : BaseRepository<ClientSoftInfo>, IClientSoft
    {
        #region 静态变量部分
        private const string PARM_CLIENTSOFT_CSID = "@CSID";
        private const string PARM_CLIENTSOFT_CSNAME = "@CSName";
        private const string PARM_CLIENTSOFT_CSVERSION = "@CSVersion";
        private const string PARM_CLIENTSOFT_REMARK = "@Remark";
        private const string PARM_CLIENTSOFT_ISVALID = "@IsValid";
        #endregion

        #region 数据检索部分
        public IList<ClientSoftInfo> LoadEntities()
        {
            return ExcuteSqlToGetEntities("ClientSoft_select");
        }

        /// <summary>
        /// Get an individual category based on a provided id
        /// </summary>
        /// <param name="categoryId">Category id</param>
        /// <returns>Details about the Category</returns>
        public ClientSoftInfo LoadEntity<T1>(T1 cSID)
        {
            SqlParameter parm = GetParameter();
            //Bind the parameter
            parm.Value = cSID;
            return ExcuteSqlToGetEntity("ClientSoft_selectbyID", parm);
        }

        public ClientSoftInfo GetClientSoftbyNV(string cSName, string cSVersion)
        {
            SqlParameter[] parms = GetNVParameters();
            parms[0].Value = cSName;
            parms[1].Value = cSVersion;
            return ExcuteSqlToGetEntity("ClientSoft_selectbyNV", parms);
        }

        public IList<ClientSoftInfo> GetClientSoftbyName(string cSName)
        {
            SqlParameter parm = new SqlParameter(PARM_CLIENTSOFT_CSNAME, SqlDbType.NVarChar, 50);
            parm.Value = cSName;
            return ExcuteSqlToGetEntities("ClientSoft_selectbyName", parm);
        }
        #endregion


        #region 参数部分
        protected SqlParameter[] GetNVParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_CLIENTSOFT_CSNAME, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_CLIENTSOFT_CSVERSION, SqlDbType.NVarChar, 50)
                };
            return parms;
        }
        #endregion


        #region 重写基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override ClientSoftInfo GetEntityRecord(SqlDataReader rdr)
        {
            ClientSoftInfo pro = new ClientSoftInfo()
                {
                    CSID = rdr.GetInt32(0),
                    CSName = rdr.GetValue(1).ToString(),
                    CSVersion = rdr.GetValue(2).ToString(),
                    Remark = rdr.GetValue(3).ToString(),
                    IsValid = rdr.GetBoolean(4)
                };
            return pro;
        }

        public override ClientSoftInfo GetEntityRecord()
        {
            ClientSoftInfo pro = new ClientSoftInfo();
            return pro;
        }

        public override string GetInsertsp()
        {
            return "ClientSoft_Insert";
        }

        public override string GetUpdatesp()
        {
            return "ClientSoft_Update";
        }

        public override string GetDeletesp()
        {
            return "ClientSoft_Delete";
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_CLIENTSOFT_CSID, SqlDbType.Int, 4);
            return Parm;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_CLIENTSOFT_CSID, SqlDbType.Int, 4),
					new SqlParameter(PARM_CLIENTSOFT_CSNAME, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_CLIENTSOFT_CSVERSION, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_CLIENTSOFT_REMARK, SqlDbType.NVarChar , 50),
                    new SqlParameter(PARM_CLIENTSOFT_ISVALID,SqlDbType.Bit,1),
                };
            return parms;
        }

        public override void SetParameters(ClientSoftInfo productType, params SqlParameter[] Parms)
        {
            Parms[0].Value = productType.CSID;
            Parms[1].Value = productType.CSName;
            Parms[2].Value = productType.CSVersion;
            Parms[3].Value = productType.Remark; 
            Parms[4].Value = productType.IsValid;
        }
        #endregion
    }
}
